using System.ComponentModel.DataAnnotations;

namespace JGSY.CMS.LowCode.Platform.Infrastructure.Configuration.Models;

/// <summary>
/// JWT 配置映射
/// </summary>
public class JwtConfiguration
{
    [Required]
    [MinLength(32, ErrorMessage = "JWT Secret must be at least 32 characters long")]
    public string Secret { get; set; } = string.Empty;
    
    public string Issuer { get; set; } = "JGSY.CMS.LowCode.Platform";
    public string Audience { get; set; } = "JGSY.CMS.LowCode.Platform.Client";
    public int ExpiryMinutes { get; set; } = 60;
    public int RefreshExpiryDays { get; set; } = 7;
    public bool ValidateIssuer { get; set; } = true;
    public bool ValidateAudience { get; set; } = true;
    public bool ValidateLifetime { get; set; } = true;
    public bool ValidateIssuerSigningKey { get; set; } = true;
}

/// <summary>
/// 服务器配置映射
/// </summary>
public class ServerConfiguration
{
    [Range(1, 65535, ErrorMessage = "Port must be between 1 and 65535")]
    public int Port { get; set; } = 4000;
    
    [Required]
    public string Environment { get; set; } = "development";
    
    public string Host { get; set; } = "localhost";
    public bool UseHttps { get; set; } = false;
    public int HttpsPort { get; set; } = 443;
    public string CertificatePath { get; set; } = string.Empty;
    public string CertificatePassword { get; set; } = string.Empty;
}

/// <summary>
/// 允许的主机配置
/// </summary>
public class AllowedHostsConfiguration
{
    public string Hosts { get; set; } = "*";
    
    /// <summary>
    /// 获取允许的主机列表
    /// </summary>
    /// <returns>主机列表</returns>
    public List<string> GetHostsList()
    {
        return Hosts.Split(';', StringSplitOptions.RemoveEmptyEntries)
                   .Select(h => h.Trim())
                   .Where(h => !string.IsNullOrEmpty(h))
                   .ToList();
    }
}
